package com.example.lee.Controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.example.lee.Fallback.Fallback;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
public class FlowLimitController {

    @GetMapping("/testA")
    public String testA(){
        try {
            TimeUnit.MILLISECONDS.sleep(8000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "-------testA";
    }

    @GetMapping("/testB")
    @SentinelResource(value = "testB",blockHandler = "blockHandlerA")
    public String testB(){
        return "--------testB";
    }

    @GetMapping("/testD")
    @SentinelResource(value = "testD",blockHandler = "blockHandlerA",fallbackClass = Fallback.class,fallback = "fallbackA")
    public String testD(){
        return "------testD";
    }

    public String blockHandlerA(BlockException blockException){
        return "blockHandlerA";
    }

}

